package Leetcode第二期;

/**
 * @author : K k
 * @date : 14:11 2020/9/19
 */
public class 二叉树的直径_543 {
    int path=1;
    public int diameterOfBinaryTree(TreeNode root) {
        dfsSolver(root);
        return path-1;
    }

    public int dfsSolver(TreeNode node){
        if(node ==null ){return 0;}
        int sum=0;
        int left=dfsSolver(node.left);
        int right=dfsSolver(node.right);
        sum=1+left+right;
        path=Math.max(path,sum);
        return Math.max(1+left,1+right);
    }
}
